﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:cs="urn:cs">

  <msxsl:script language="C#" implements-prefix="cs">
    <![CDATA[
         public string GetIterationFilter() {
             return (DateTime.Now.ToString("MM/yyyy"));
         }
         
        public bool IsCompleted(string d1)  {
            return d1.Trim().Equals("Completed");
        }
    
     ]]>
  </msxsl:script>
  
  
  
  <xsl:param name="from" />
  <xsl:template match="/">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
          h1 {
          color: green;
          font-family: Tahoma;
          font-size:16px;
          }

          table {
          font-family: Tahoma;
          font-size:12px;}

          td {
          padding-left:15px;
          padding-right:15px;
          padding-top:4px;
          padding-bottom:4px;
          }

          #left{
          float:left;
          width:40%;
          overflow:hidden;
          }

          #right{
          float:left;
          width:60%;
          overflow:hidden;
          }
        </style>
        <title>Current Work Items</title>
      </head>
      <body>

         <xsl:call-template name="ReportData">
          <xsl:with-param name="filter" select="1" />
        </xsl:call-template>

        <p>&#160;</p>
        <hr></hr>
        
        <xsl:call-template name="ReportData">
          <xsl:with-param name="filter" select="0" />
        </xsl:call-template>

      </body>
    </html>
  </xsl:template>
  <!--=============================================================================================================================================================-->
  <!-- Template to display all data                                                                                                                                -->
  <!--=============================================================================================================================================================-->
  <xsl:template name="ReportData">
    <xsl:param name="filter" />
    <H1>
      <xsl:choose>
        <xsl:when test="$filter = 1">
          <xsl:text>Current Work Items ( </xsl:text>
          <xsl:value-of select="//workitems/@rdate" />
          <xsl:text> )</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>Completed Work Items</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </H1>
    <table>
      <tr>
        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          No
        </th>

        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          ID
        </th>

        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          Title
        </th>
        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          Assigned To
        </th>

        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          State
        </th>

        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          Iteration
        </th>

        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          PR
        </th>

        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          Staging
        </th>

        <th noWrap="" style="BORDER-TOP: ghostwhite 1px solid; HEIGHT: 20px; BORDER-BOTTOM: dimgray 1px solid; PADDING-BOTTOM: 5px; TEXT-ALIGN: center; PADDING-TOP: 5px; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BACKGROUND-COLOR: gainsboro">
          Notes
        </th>

      </tr>



      

      <xsl:choose>
        <xsl:when test="$filter = 1">
          <xsl:call-template name="openitems">
            <xsl:with-param name="filter" select="$filter" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="doneitems">
            <xsl:with-param name="filter" select="$filter" />
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>

    </table>
  </xsl:template>



  <!--=============================================================================================================================================================-->
  <!-- Template to display the body data                                                                                                                            -->
  <!--=============================================================================================================================================================-->
  <xsl:template name="doneitems">
    <xsl:variable name="datefilter" select="cs:GetIterationFilter()" />
    <xsl:for-each select="//workitem[wstate = 'Completed' and starts-with(witeration, $datefilter)]">
      <xsl:sort select="witeration" order="descending" />
      <xsl:call-template name="datarow">
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>
  <!--=============================================================================================================================================================-->
  <!-- Template to display the body data                                                                                                                            -->
  <!--=============================================================================================================================================================-->
  <xsl:template name="openitems">
    <xsl:for-each select="//workitem[cs:IsCompleted(wstate) = 0]">
         <xsl:sort select="concat(wstate, wnotes)" order="descending" />
      <xsl:call-template name="datarow">
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>
  <!--=============================================================================================================================================================-->
  <!-- Template to display a data row                                                                                                                            -->
  <!--=============================================================================================================================================================-->
  <xsl:template name="datarow">
    <tr>
      <xsl:if test="(position() mod 2 = 0)">
        <xsl:attribute name="bgcolor">#EEEEFF</xsl:attribute>
      </xsl:if>

      <td style="text-align: center;">
        <xsl:value-of select="position()" />
      </td>

      <td style="text-align: center;">
        <a>
          <xsl:attribute name="href">
            <xsl:text disable-output-escaping="yes">https://mseng.visualstudio.com/TechnicalContent/_workitems?id=</xsl:text>
            <xsl:value-of select="wid" />
            <xsl:text disable-output-escaping="yes">&amp;triage=true&amp;fullScreen=false&amp;_a=edit</xsl:text>
          </xsl:attribute>
          <xsl:attribute name="target">
            <xsl:text disable-output-escaping="yes">_blank</xsl:text>
          </xsl:attribute>
          <xsl:value-of select="wid" />
        </a>
      </td>


      <td style="text-align: left;">
        <xsl:value-of select="wtitle" />
      </td>

      <td style="text-align: left;">
        <xsl:value-of select="wassignedto" />
      </td>

      <td style="text-align: left;">
        <xsl:value-of select="wstate" />
      </td>

      <td style="text-align: left;">
        <xsl:value-of select="witeration" />
      </td>

      <td style="text-align: left;">
        <a>
          <xsl:attribute name="href">
            <xsl:value-of select="wpr" />
          </xsl:attribute>
          <xsl:attribute name="target">
            <xsl:text disable-output-escaping="yes">_blank</xsl:text>
          </xsl:attribute>
          <xsl:value-of select="substring-after(wpr, '/pull/')" />
        </a>
      </td>

      <td style="text-align: left;">
        <xsl:if test="(string-length(wreview) > 2)">
          <a>
            <xsl:attribute name="href">
              <xsl:value-of select="wreview" />
            </xsl:attribute>
            <xsl:attribute name="target">
              <xsl:text disable-output-escaping="yes">_blank</xsl:text>
            </xsl:attribute>
            <xsl:text>Link</xsl:text>
          </a>
        </xsl:if>
      </td>

      <td style="text-align: left;">
        <xsl:value-of select="wnotes" />
      </td>




    </tr>
  </xsl:template>
</xsl:stylesheet>
